package l1j.server.server.datatables;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

import l1j.server.L1DatabaseFactory;
import l1j.server.server.utils.SQLUtil;
import l1j.server.server.utils.collections.Maps;

public class DeleteItemPriceTable {
	private static DeleteItemPriceTable _instance;
	
	public static DeleteItemPriceTable getInstance() {
		return _instance;
	}
	
	public static void initilize() {
		_instance = new DeleteItemPriceTable();
	}
	
	private Map<Integer, Integer> _allItemPrice = Maps.newMap();
	
	private DeleteItemPriceTable() {
		int item_id;
		int delete_price;
		Connection con = null;
		PreparedStatement pstm = null;
		ResultSet rs = null;
		try {
			con = L1DatabaseFactory.getInstance().getConnection();
			pstm = con.prepareStatement("SELECT * FROM x_item_deleteprice");
			
			rs = pstm.executeQuery();
			while (rs.next()) {
				item_id = rs.getInt("item_id");
				delete_price = rs.getInt("selling_price");
				
				_allItemPrice.put(item_id, delete_price);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			SQLUtil.close(rs);
			SQLUtil.close(pstm);
			SQLUtil.close(con);
		}
	}
	
	public int getDeletePrice(int itemId) {
		int value = 1;
		if (_allItemPrice.containsKey(itemId)) {
			value = _allItemPrice.get(itemId);
		}
		return value;
	}
}